/***************************************************************************
 * Slink.Generator -- Copyright Bit Armory Labs 2007
 *
 * FILE:     SlinkClass.cs, 116 code lines, [3.36 KB]
 * DATE:     8/27/2007 10:46 PM
 * MODIFIED: 8/27/2007 11:18 PM
 * PATH:     C:\Programming\Projects\Slink\Slink.Generator
 *
 * NAMESPACE: Slink.Generator
 * CLASS:     SlinkClass
 *
 * AUTHOR:   Brian Chavez (Cowboy), bchavez@bitarmory.com
 *
 *                        Licence
 *
 * This library, code generator, and source code
 * is licensed under the terms and conditions defined in the GNU Public
 * License. You are free to use it for non-commercial purposes.
 * If you are going to use any part of it in a commercial 
 * application, contact me and we can work something out.
 * You may use the code generated output of Slink and Slink
 * as a development tool in both commercial and 
 * non-commercial applications.
 *
 * THE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS", WITHOUT WARRANTY
 * OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THIS
 * SOFTWARE.
 ***************************************************************************/

using System;
using Slink.Core;
using System.IO;
using TaHoGen.Generators;
namespace Slink.Generator
{
    public class SlinkClass
    {
        private SlinkManagedWebProject parentProject;
        private NamespaceRulesElement fileRule;
        private string fullPathOnDisk;

        /// <summary>
        /// Initializes a new instance of the SlinkClass class.
        /// </summary>
        /// <param name="parentProject"></param>
        /// <param name="fileRule"></param>
        /// <param name="fullPathOnDisk"></param>
        public SlinkClass( SlinkManagedWebProject parentProject, NamespaceRulesElement fileRule, string fullPathOnDisk )
        {
            this.parentProject = parentProject;
            this.fileRule = fileRule;
            this.fullPathOnDisk = fullPathOnDisk;
        }


        public string ClassName
        {
            get
            {
                return this.GetClassName();
            }
        }

        public string FullPathOnDisk
        {
            get
            {
                return fullPathOnDisk;
            }
        }


        public string PageUrl
        {
            get
            {
                return this.GetPageUrl();
            }
        }

        public string PageTildeUrl
        {
            get
            {
                return this.GetTildeUrl();
            }
        }

        public string NamespaceLocation
        {
            get
            {
                return SlinkNamespace.GetNamespace( this.fullPathOnDisk, this.fileRule, this.parentProject );
            }
        }
        

        /// <summary>
        /// Get class name for aspx file
        /// </summary>
        private string GetClassName()
        {
            string resultClassName = System.Text.RegularExpressions.Regex.Replace( Path.GetFileNameWithoutExtension( this.fullPathOnDisk ), @"[^\w]", "_" );
            return resultClassName;
        }
        /// <summary>
        /// Get absolute url for aspx file
        /// </summary>
        private string GetPageUrl()
        {
            string fileFullPath = Path.GetFullPath( this.fullPathOnDisk );

            string relativeUrl = fileFullPath.Replace( this.parentProject.VsWebProjectFullFilePathOnDisk, "" ).Replace(Path.DirectorySeparatorChar, '/');

            return relativeUrl;
        }
        /// <summary>
        /// Get tilde url for aspx file
        /// </summary>
        private string GetTildeUrl()
        {
            return "~" + this.GetPageUrl();
        }

        /// <summary>
        /// Get class text generator
        /// </summary>
        /// <returns>Text generator</returns>
        public TextGenerator GetClassTextGenerator()
        {
            return ClassTemplateFactory.CreateClassTextGenerator( this.ClassName, this.PageUrl, this.PageTildeUrl );
        }
    }
}